package net.xxcxcxcx.xc_enhancedmob.skills.environment;

import net.minecraft.entity.attribute.EntityAttributeInstance;
import net.minecraft.entity.attribute.EntityAttributeModifier;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import net.xxcxcxcx.xc_enhancedmob.config.skill.SkillConfig;
import net.xxcxcxcx.xc_enhancedmob.skills.BaseSkill;
import net.xxcxcxcx.xc_enhancedmob.skills.SkillRarity;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class BaseEnvironmentSkill extends BaseSkill {
    public static UUID uuid = UUID.fromString("66457ab2-c4d2-832c-ec25-4aefbfeafc32");

    public BaseEnvironmentSkill() {
        this(1);
    }

    public BaseEnvironmentSkill(int level) {
        super(level);
    }

    public BaseEnvironmentSkill(NbtCompound nbtCompound) {
        super(nbtCompound);
    }

    public static List<Integer> integers() {
        List<Integer> list = new ArrayList<>();
        return list;
    }

    @Override
    public SkillConfig getDefaultConfig() {
        SkillConfig skillConfig = super.getDefaultConfig();
        skillConfig.setMessage(getConfigMessage(skillConfig));
        return skillConfig;
    }

    @Override
    public String getConfigMessage(SkillConfig skillConfig) {
        return "这是一个测试环境技能，主要用于测试环境技能的完成程度和技能效果，你在游戏内不应该看到这段文字。";
    }

    @Override
    public Text getText() {
        LiteralText literalText = new LiteralText("");
        TranslatableText text = new TranslatableText("skill." + getSkillRarity() + "." + getName());
        text.formatted(Formatting.RED);
        literalText.append(text);
        return literalText;
    }

    public SkillRarity getSkillRarity() {
        return SkillRarity.Environment;
    }

    @Override
    public boolean onAttribute(MobEntity mobEntity) {
        EntityAttributeModifier modifier = new EntityAttributeModifier(uuid, getName(), 1, EntityAttributeModifier.Operation.fromId(0));
        EntityAttributeInstance entityAttributeInstance = mobEntity.getAttributeInstance(EntityAttributes.GENERIC_MAX_HEALTH);
        if (entityAttributeInstance == null) return true;
        if (!entityAttributeInstance.hasModifier(modifier))
            entityAttributeInstance.addPersistentModifier(modifier);
        return true;
    }

    /*

    @Override
    public boolean canUseAbility(MobEntity mobEntity) {
        return getSkillUsecount() < getMaxUseCount();
    }

    @Override
    public boolean onTreat(MobEntity mobEntity, Ref<Float> amount) {
        amount.setValue(amount.getValue() * 1.5f);
        return true;
    }

    @Override
    public boolean onDeath(LivingEntity attacker, MobEntity target, DamageSource source, boolean ismob, boolean remote) {
        if (canUseAbility(target)) {
            setSkillUsecount(getSkillUsecount() + 1);
            target.playSound(SoundEvents.ITEM_TOTEM_USE, 1f, 1f);
            target.setHealth(target.getMaxHealth());
            target.clearStatusEffects();
            target.addStatusEffect(new StatusEffectInstance(StatusEffects.REGENERATION, 900, 1));
            target.addStatusEffect(new StatusEffectInstance(StatusEffects.ABSORPTION, 100, 1));
            target.addStatusEffect(new StatusEffectInstance(StatusEffects.FIRE_RESISTANCE, 800, 0));
            target.world.sendEntityStatus(target, (byte) 35);
            return false;
        }
        return true;
    }

    @Override
    public boolean onStartAttack(MobEntity attacker, LivingEntity entity) {
        if (entity != null) entity.addStatusEffect(new StatusEffectInstance(StatusEffects.HUNGER, 900, 1));
        return true;
    }

    @Override
    public boolean onAttack(MobEntity attacker, LivingEntity target, DamageSource source, Ref<Float> amount, boolean ismob, boolean remote) {
        if (target != null) target.addStatusEffect(new StatusEffectInstance(StatusEffects.HUNGER, 900, 1));
        return true;
    }

    @Override
    public boolean onDamaged(LivingEntity attacker, MobEntity target, DamageSource source, Ref<Float> amount, boolean ismob, boolean remote) {
        if (attacker != null) attacker.addStatusEffect(new StatusEffectInstance(StatusEffects.HUNGER, 900, 1));
        amount.setValue(amount.getValue() / 2);
        return true;
    }

    @Override
    public boolean onAbilityUse(MobEntity mobEntity) {
        if (getSkilltime() < mobEntity.world.getTime() && mobEntity.getHealth() < mobEntity.getMaxHealth() * 0.6) {
            setSkilltime(mobEntity.world.getTime() + getCooldown());
            mobEntity.heal(10);
        }
        return true;
    }

    @Override
    public boolean passiveApply(MobEntity mobEntity) {
        if (mobEntity.world.getTime() % 5 == 0) mobEntity.heal(1);
        return true;
    }*/
}
